<section id="main-content">
  <section class="wrapper">
    <!--state overview end-->
    <div class="row">
      <div class="col-lg-12">
        <div class="alert alert-block alert-warning fade in">
          <button data-dismiss="alert" class="close close-sm" type="button">
            <i class="icon-remove"></i>
          </button>
          <strong>注意事项：</strong><br>
          1、请在发起人员借调时，先与相关人员沟通确认需要借调的具体人员姓名和工号，以及人力费用归属的项目，然后再到系统上登记和确认；<br>
          2、借调一旦生效，具体工作量通过借调人员的OKR子任务周报体现，需要人员使用方的项目经理和人员输出方注重对人员OKR子任务周报的填写和确认。
        </div>

        <section class="panel">
          <div class="panel-body">
            <div class="form-group customerForm">
              <label class="col-sm-2 control-label">公司/事业部</label>
              <div class="col-sm-10">
                <select name="compId" ng-model="companys" id="companys" class="form-control" disabled onchange="getUser(this.value)" certus-required>
                  <option value="">请选择</option>
                  <option value="STSJT">赛特斯集团</option>
                  <option value="HFKJ">浩方科技</option>
                  <option value="HFXX">浩方信息</option>
                  <option value="SYB-DL">电力事业部</option>
                  <option value="SYB-RX">融合运维事业部</option>
                </select>
              </div>
            </div>
            <div class="form-group customerForm">
              <label class="col-sm-2 control-label">归属项目</label>
              <div class="col-sm-10">
                <input type="text" id="proName" name="proName" value="{{proName}}" disabled placeholder="自动检索项目名称" class="form-control">
                <input type="hidden" value="{{proId}}" name="proId" certus-required id="proId" />
              </div>
            </div>
            <div class="form-group customerForm">
              <label class="col-sm-2 control-label">归属项目下的合同</label>
              <div class="col-sm-10">
                <select class="form-control" disabled name="contractId" id="contractId">
                  <option value="">请选择</option>
                </select>
              </div>
            </div>
          </div>
        </section>

        <section class="panel">
          <header class="panel-heading add-heading">
            人员借调列表
          </header>
          <div class="panel-body">
            <div id="userlistContainer" class="dlshouwen-grid-container"></div>
          </div>
        </section>
        <section class="panel">
          <header class="panel-heading">
            理由/备注说明
          </header>
          <div class="panel-body">
            <div class="form-group customerForm">
              <textarea class="form-control" maxlength="120" id="loanComments" disabled placeholder="字符长度限制(120字以内)">{{loanComments}}</textarea>
            </div>
            
          </div>
        </section>


        <section class="panel">
            <div class="panel-body">
                <p class="default-buttons">
                    <a href="javascript:void(0);" class="button-back btn btn-info" onclick="window.history.back()">返回</a>
                    <a href="javascript:void(0);" class="button-next  btn btn-info" onclick="window.history.back()">确认</a>
                </p>
            </div>
        </section>

        <section class="panel">
          <div class="panel-heading">
            审批记录
          </div>
          <div class="panel-body">
            <ul class="tp-ulst" id="containerUl">
              <li>
                <span>人员姓名</span><span>修改时间</span><span>处理结果</span>
              </li>
            </ul>
          </div>
        </section>
      </div>
    </div>
  </section>
</section>
<script type="text/javascript">
    function findLoanDetail($scope, CertusFormAjax,$routeParams) {
        CertusFormAjax.ajax("findSeProList",{},function(response){
            var nhlTeams = [];
            var data = response.data;
            for (var i=0;i<data.length;i++){
                var arr={};
                arr.name=data[i].proName;
                arr.id = data[i].id;
                nhlTeams.push(arr);
            }
            //自动补全
            var nhl = $.map(nhlTeams, function (obj) {
                return {
                    value: obj.name,
                    data: { category: obj.id }
                };
            });
            // Initialize autocomplete with local lookup:
            $('#proName').devbridgeAutocomplete({
                lookup: nhl,
                minChars: 1,
                onSelect: function (suggestion) {
                    $("#proId").val(suggestion.data.category);
                    getProContract(suggestion.data.category,"");
                },
                showNoSuggestionNotice: true,
                noSuggestionNotice: 'Sorry, no matching results'
            });

        });

        this.getProContract = function (proId,contractId) {
            CertusFormAjax.ajax("contractProgresss",{"projId":proId},function (response) {
                var data = response.data;
                $("#contractId").html("");
                $("#contractId").append('<option value="">请选择</option>');
                for (var i=0;i<data.length;i++){
                    var ctinfo = data[i].contractInfo;
                    $("#contractId").append("<option value='"+ctinfo.contractNo+"'>"+ctinfo.contractNo+"</option>")
                }
                if (contractId!=""){
                    $("#contractId").val(contractId);
                }
            });
        };

        this.loadlb = function (paramArr) {
            $("#userlistContainer").empty();
            var userlistColumns = [{
                id: 'deptName',
                title: '借调部门',
                type: 'string',
                width: 150,
                columnClass: 'text-center'
            }, {
                id: 'loanType',
                title: '人员类别',
                type: 'string',
                width: 75,
                columnClass: 'text-center',
            }, {
                id: 'userName',
                title: '人员姓名',
                type: 'string',
                width: 75,
                columnClass: 'text-center'
            }, {
                id: 'workStart',
                title: '开始日期',
                type: 'date',
                columnClass: 'text-center',
                format: 'yyyy-MM-dd',
                otype: 'time_stamp_ms'
            }, {
                id: 'workEnd',
                title: '结束日期',
                type: 'date',
                columnClass: 'text-center',
                format: 'yyyy-MM-dd',
                otype: 'time_stamp_ms'
            },{
                id: 'invoice',
                title: '投入占比(%)',
                type: 'string',
                width: 90,
                columnClass: 'text-center',
            }, {
                id: 'comments',
                title: '工作任务',
                type: 'string',
                columnClass: 'text-center',
            }];
            var userlistOption = {
                lang: 'zh-cn',
                ajaxLoad: false,
                exportFileName: '人员借调列表',
                datas: paramArr,
                columns: userlistColumns,
                gridContainer: 'userlistContainer',
                tools: ''
            };
            var userlistGrid = $.fn.dlshouwen.grid.init(userlistOption);
            userlistGrid.load();
        };

        CertusFormAjax.ajax('findRhLocs',{"processId":$routeParams.id},function (response) {
            var tlmBean = response.data.tlmBean;
            $scope.companys = tlmBean.companyCode;
            $scope.id = tlmBean.id;
            $scope.proName = tlmBean.proName;
            getProContract(tlmBean.proId,tlmBean.contractId);
            $scope.proId = tlmBean.proId;
            $scope.loanComments = tlmBean.loanComments;

            var personList = response.data.personList;
            loadlb(personList);
        });

        CertusFormAjax.ajax("findSpNodes", {
            "processId": $routeParams.id
        }, function (result) {
            var data = result.data;
            var html = "";
            var dlength = data.length;
            for (var i = 0; i < dlength; i++) {
                html+="<li><span>"+data[i].createUser+"</span><span>"+data[i].createTime+"</span>";
                if (data[i].nodeFlag==1){
                    html+="<span>发起申请</span>";
                }else if (data[i].nodeFlag==2){
                    html+="<span>拒绝，审批意见："+data[i].opinionMsg+"</span>";
                }else if (data[i].nodeFlag == 3){
                    html+="<span>退回，审批意见："+data[i].opinionMsg+"</span>";
                }else if (data[i].nodeFlag==4){
                    html+="<span>同意，审批意见："+data[i].opinionMsg+"</span>";
                }else if (data[i].nodeFlag==5){
                    html+="<span>部门审批通过，审批意见："+data[i].opinionMsg+"</span>";
                }else{
                    html+="<span>区域经理审批通过，审批意见："+data[i].opinionMsg+"</span>";
                }
                html+="</li>";
            };
            $("#containerUl").append(html);
        });
    }
</script>